package com.cdeledu.thread.concurrent;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**递归调用会出现死循环
 * @author DELL
 *
 */
public class ConcurrentHashMapBug {

	private Map<Integer, Integer> cache = new ConcurrentHashMap<>(15);

	public static void main(String[] args) {
		ConcurrentHashMapBug ch = new ConcurrentHashMapBug();
		System.out.println(ch.fibonaacci(80));
	}

	public int fibonaacci(Integer i) {
		if (i == 0 || i == 1) {
			return i;
		}

		return cache.computeIfAbsent(i, (key) -> {
			System.out.println("fibonaacci : " + key);
			return fibonaacci(key - 1) + fibonaacci(key - 2);
		});
	}

}
